package org.uu.mybatisplus.component;

import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Endpoint(id = "runtime")
public class RuntimeEndpoint{

    private final StartupTimeListener startupTimeListener;

    private String runtime;

    public RuntimeEndpoint(StartupTimeListener startupTimeListener) {
        this.startupTimeListener = startupTimeListener;
        this.runtime = LocalDateTime.now().toString();
    }

    @ReadOperation
    public String getRuntime() {
        long startupTime = System.currentTimeMillis() - startupTimeListener.getStartupTime();
        return String.format("startup: %s; runtime: %s",runtime , startupTime);
    }
}